<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
		xmlns:ui="http://java.sun.com/jsf/facelets"
		xmlns:f="http://java.sun.com/jsf/core" 
		xmlns:c="http://java.sun.com/jstl/core" 
		xmlns:h="http://java.sun.com/jsf/html"
		xmlns:a4j="http://richfaces.org/a4j"
		xmlns:rich="http://richfaces.org/rich">
		
	<ui:composition>
					<table width="100%">
						<tr>
							<td  valign="top">									
								<h:panelGrid columns="2">
									<h:outputLabel value="Name: "/>
									<h:panelGroup>									
										<table width="250px" class="norender">
											<tr>												
												<td colspan="1" align="left" width="50%">
													<h:inputText id="currentAttendentSel" value="#{model.attendent.name}"/>
													<h:panelGroup>									
														<rich:suggestionbox for="currentAttendentSel" status="selCurAt"
															suggestionAction="#{controller[existing]}" minChars="#{showSuggestion ? 2 : 100}" nothingLabel="Not found" var="result">
															<h:column>
																<h:outputText value="#{result.name}" />
															</h:column>
															<a4j:support event="onselect" action="#{controller[selectMethod]}" 
																status="selCurAt" reRender="atAge,atIdn,atIdt,atSex,atPro,atRel" />
														</rich:suggestionbox>
													</h:panelGroup>
												</td>
												<td colspan="1" align="left" width="20%">
													<a4j:status forceId="true" id="selCurAt">
														<f:facet name="start">
															<h:graphicImage value="/images/im1.gif" />
														</f:facet>
													</a4j:status>
												</td>											
											</tr>										
										</table>
									</h:panelGroup>									
									<h:outputLabel value="Relationship" />
									<rich:comboBox id="atRel"	value="#{model.attendent.relationship}"
																	suggestionValues="#{relationshipDao.all}"
																	converter="#{relationshipConverter}"
																	enableManualInput="false"/>
									<h:outputLabel value="Sex:" />
									<h:selectOneRadio id="atSex" value="#{model.attendent.sex}">
														<f:selectItem itemLabel="Male" itemValue="M"/>
														<f:selectItem itemLabel="Female" itemValue="F"/>
													</h:selectOneRadio>	
									<h:outputLabel value="Age:" />
									<h:inputText id="atAge" value="#{model.attendent.age}"/>
									<h:outputLabel value="ID Card Type:" />
									<rich:comboBox id="atIdt"	value="#{model.attendent.idCardType}" 
																	suggestionValues="#{idCardTypeDao.all}"
																	converter="#{idCardTypeConverter}"
																	enableManualInput="false"/>
									<h:outputLabel value="ID Card Number:" />
									<h:inputText id="atIdn" value="#{model.attendent.idCardNumber}"/>
									<h:outputLabel value="Profession" />
									<rich:comboBox id="atPro"	value="#{model.attendent.profession}"
																	suggestionValues="#{professionDao.all}"
																	converter="#{professionConverter}"
																	enableManualInput="false"/>																				
									
								</h:panelGrid>
								<div align="center">
									<a4j:commandButton value="Add"	action="#{controller[addMethod]}" 
																	reRender="dtblCurrentAttendents,#{reRender}"
																	oncomplete="if(#{controller.error})alert('#{controller.errors[0]}');"/>
								</div>							
							</td>
							<td valign="top">
								<rich:dataTable id="dtblCurrentAttendents" 
												value="#{data}" var="aBean" align="center">
									<f:facet name="header">
										<h:outputText value="Current Attendents"/>
									</f:facet>							
									<rich:column>
										<f:facet name="header">
											<h:outputText value="Delete"/>
										</f:facet>							
										<a4j:commandButton image="/resrc/images/cross1.jpg" 
															style="width:15px;height:15px;" 
															action="#{controller[removeMethod]}" reRender="dtblCurrentAttendents,#{reRender}"/>
									</rich:column>
									<rich:column>
										<f:facet name="header">Name</f:facet>
										<h:outputText value="#{aBean.attendent.name} "/>
									</rich:column>
									<rich:column>
										<f:facet name="header">Relationship</f:facet>
										<h:outputText value="#{aBean.attendent.relationship}" converter="#{relationshipConverter}"/>
									</rich:column>																	
									<rich:column>
										<f:facet name="header">Sex</f:facet>
										<h:outputText value="#{aBean.attendent.sex == 'M' ? 'Male' : 'Female'} "/>
									</rich:column>
									<rich:column>
										<f:facet name="header">Age</f:facet>
										<h:outputText value="#{aBean.attendent.age} "/>
									</rich:column>
									<rich:column>
										<f:facet name="header">ID</f:facet>
										<div>
											<h:outputText value="#{aBean.attendent.idCardType}" converter="#{idCardTypeConverter}"/>
										</div>
										<div>#{aBean.attendent.idCardNumber}</div>							
									</rich:column>
									<rich:column>
										<f:facet name="header">Profession</f:facet>
										<h:outputText value="#{aBean.attendent.profession}" converter="#{professionConverter}"/>
									</rich:column>
									
									<c:if test="#{empty data or data['rowCount'] le 0}">
										<f:facet name="footer">
											<h:outputText value="No Attendents Added..." />
										</f:facet>
									</c:if>					
								</rich:dataTable>															
							</td>
						</tr>
					</table>	
	</ui:composition>	
</html>
